package com.youlv.yl.vo;

import com.youlv.yl.config.SystemConfig;
import lombok.Data;

/**
 * @author fenghe
 * @date 2022/1/2 8:59
 */
@Data
public class R {
    private int code;
    private String msg;
    private Object data;
    private String message;
    // 贫血模式  充血模式  DDD模型

    public static R createR(int code, String msg, Object data) {
        R r = new R();
        r.setCode(code);
        r.setData(data);
        r.setMsg(msg);

        return r;
    }

    public R() {
    }

    public R(int code, Object data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static R ok(String msg, Object data) {
        return createR(SystemConfig.R_OK, msg, data);
    }

    public static R ok(Object data) {
        return createR(SystemConfig.R_OK, "OK", data);
    }

    public static R ok() {
        return createR(SystemConfig.R_OK, "OK", null);
    }

    public static R fail(String msg) {
        return createR(SystemConfig.R_FAIL, msg, null);
    }
    public static R ok(Integer status, String token) {
        return createR(status, "OK", token);
    }

    public static R fail(Integer status, String msg) {
        return createR(status, msg, null);
    }
}
